package com.cskaoyan.gateway.controller.shopping;

import com.google.common.annotations.VisibleForTesting;
import com.mall.commons.result.ResponseData;

import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 创建日期: 2022-01-20-15-46
 * author : XGQ
 * description: 列举所有商品种类
 */
@RestController
@RequestMapping("shopping")
public class CategoriesController {

    @Reference(timeout = 10000, retries = 0, check = false)
    IProductCateService iProductCateService;

    @GetMapping("categories")
    @Anoymous
    public ResponseData getShowCategories(String sort) {
        AllProductCateRequest request = new AllProductCateRequest();
        if (sort != null){
            sort = "desc";
        } else {
            sort = "asc";
        }
        request.setSort(sort);

        AllProductCateResponse response = iProductCateService.getAllProductCate(request);
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
